<template>
  <div class="page" @scroll="onPageScroll">
    <HeaderBar :fixed="true" :theme="theme" :active="'technology'"/>
    <div class="banner">
      <img oncontextmenu="return false" :src="info.develop_photo" class="fit-img" alt="" />
      <div class="banner-inner">
        <div class="banner-title wow fadeInUp" data-wow-duration="1s" data-wow-delay="0.3s">{{ info.develop_title }}</div>
        <div class="banner-desc wow fadeInUp" data-wow-duration="1s" data-wow-delay="0.4s" v-html="info.develop_titles"></div>
      </div>
      <div class="banner-arr">
        <img src="@/assets/images/arr_d.svg" class="icon">
      </div>
    </div>
    <div class="tech-user">
      <div class="tech-user-main">
        <div class="tech-user-hd flex-between">
          <div class="user-title wow fadeInUp" data-wow-duration="1s" data-wow-delay="0.3s">{{ info.develop_peo_title }}</div>
          <div class="user-desc wow fadeInUp" data-wow-duration="1s" data-wow-delay="0.3s" v-html="info.develop_peo_titles"></div>
        </div>
        <div class="tech-user-photo">
          <img oncontextmenu="return false" :src="info.develop_peo_photo" class="fit-img" >
          <div class="tech-user-tag">研发团队人员形象照</div>
        </div>
      </div>
    </div>
    <div class="lab-container">
      <div class="lab-box">
        <div class="lab-box-section">
          <div class="lab-item">
            <div class="lab-icon flex-center">
              <img src="@/assets/images/icon_slide_red.svg" alt="">
            </div>
            <div class="lab-right">
              <img oncontextmenu="return false" :class="{'active': curLabIndex == index}" v-for="(item, index) in labList" :key="index" :src="item.photo" alt="" class="lab-photo fit-img">
            </div>
          </div>
        </div>
        <div class="lab-left">
          <div class="text-wrapper">
            <div class="lab-card" v-for="(item, index) in labList" :key="index" :id="`lab-card-${index}`">
              <div class="lab-main" :class="{active: curLabIndex == index}" @click="showLab(index)">
                <div class="lab-tag">{{ item.tag }}</div>
                <div class="lab-title">{{ item.title }}</div>
                <div class="lab-line"></div>
                <div class="lab-content" v-html="item.content"></div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="patent-box">
      <div class="patent-container">
        <div class="patent-hd  wow fadeInUp" data-wow-duration="1s" data-wow-delay="0.3s">
          <div class="patent-left">
            <div class="title">{{ info.develop_patent_title }}</div>
            <div class="desc" v-html="info.develop_patent_titles"></div>
          </div>
          <div class="patent-right">
            <div class="patent-photos">
              <div class="patent-item" v-for="(item, index) in patentList" :key="index">
                <div class="photo">
                  <img oncontextmenu="return false" :src="item.photo">
                </div>
                <div class="label">{{ item.title }}</div>
              </div>
            </div>
          </div>
        </div>
        <div class="patent-main flex-between wow fadeInUp" data-wow-duration="1s" data-wow-delay="0.3s">
          <div class="patent-data" v-for="(item, index) in dataList" :key="index">
            <div class="key f-number" v-if="showData"> 
              <count-up 
                :end-val="item.key"
                :duration="2.5"
                :delay="2.5"
                :decimal-places="0"
                :options="{useGrouping: false}"></count-up>
              <span v-if="item.unit">+</span></div>
            <div class="title">{{ item.title }}</div>
          </div>
        </div>
      </div>
      
    </div>
    <FooterBar />
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import { formatText, hideLoading } from '../../utils/utils'
import { getDevelopHomeInfo, getPatentList, getLabList } from '@/api/tech' 
import Swiper from 'swiper'
import { Mousewheel, Navigation } from 'swiper/modules'
import 'swiper/scss';
import 'swiper/scss/navigation';
import WOW from 'wow.js'
import CountUp from 'vue-countup-v3'

import HeaderBar from '@/components/HeaderBar/index.vue'
import FooterBar from '@/components/FooterBar/index.vue'

const theme = ref('transparent')
const info = ref({})
const patentList = ref([])
const dataList = ref([])
const labList = ref([])
const curLabIndex = ref(0)
const showData = ref(false)
let labSwiper

onMounted(() => {
  loadData()
  const wow = new WOW({
    scrollContainer: '.page',
    offset: 100
  })
  wow.init()
});

const onPageScroll = e => {
  const scrollTop = e.target.scrollTop
  if (scrollTop > 100) {
    theme.value = 'white'
  } else {
    theme.value = 'transparent'
  }
  const halfWindowHeight = document.documentElement.clientHeight / 2
  const top = document.querySelector('.lab-container').offsetTop
  if (labList.value.length > 0) {
    for (let i=0; i< labList.value.length; i++) {
      if (scrollTop > top - halfWindowHeight + document.querySelector('#lab-card-' + i).offsetTop + 40 ) {
        curLabIndex.value = i
      }
    }
  } 
  const countTop = document.querySelector('.patent-data').offsetTop
  if (scrollTop > countTop - halfWindowHeight) {
    showData.value = true
  }
  
}
const loadData = () => {
  getDevelopHomeInfo().then(res => {
    info.value = res.data.list
    info.value.develop_titles = formatText(info.value.develop_titles)
    info.value.develop_peo_titles = formatText(info.value.develop_peo_titles)
    info.value.develop_lab_titles = formatText(info.value.develop_lab_titles || '')
    info.value.develop_patent_titles = formatText(info.value.develop_patent_titles)
    let _list = []
    for(let key in info.value.develop_patent_data) {
      _list.push({
        key: Number(key.split('+')[0]),
        unit: key.indexOf('+') > -1 ? '+' : '',
        title: info.value.develop_patent_data[key]
      })
    }
    dataList.value = _list
  })
  getPatentList().then(res => {
    patentList.value = res.data
  })
  getLabList().then(res => {
    labList.value = res.data
    setTimeout(() => {
      hideLoading()
    }, 300)
  })

};
const initLabSwiper = () => {
  const screenWidth = document.body.clientWidth;
  
};

const showLab = index => {
  curLabIndex.value = index
  labSwiper.slideTo(index, 400*2000)
};

</script>

<style lang="scss">
@use '@/assets/style/common.scss';
.page {
  width: 100%;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
}
.banner {
  width: 100%;
  height: 100vh;
  position: relative;
}
.banner-inner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40rem /* 640/16 */;
  z-index: 10;
  .banner-title {
    text-align: center;
    color: #FFFFFF;
    font-size: 3.125rem /* 50/16 */;
    line-height: 1;
    font-weight: 500;
  }
  .banner-desc {
    margin-top: 1.875rem /* 30/16 */;
    font-size: 1.0625rem /* 17/16 */;
    line-height: 2.375rem /* 38/16 */;
    text-align: center;
    color: #F2F2F2;
  }
}
.banner-arr {
  width: .75rem /* 12/16 */;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 2.5rem /* 40/16 */;
  .icon {
    width: 100%;
    animation: arr infinite linear 1s;
  }
}
@keyframes arr {
  0% {
    transform: translateY(-2px);
  }
  100% {
    transform: translateY(2px);
  }
}
.tech-user {
  width: 100%;
  padding: 4.375rem /* 70/16 */ 0 4.8125rem /* 77/16 */;
  background: #FFFFFF;
}
.tech-user-main {
  width: 91.66vw;
  margin: 0 auto;

}
.tech-user-hd {
  margin-bottom: 2.5rem /* 40/16 */;
  width: 100%;
  .user-title {
    font-size: 2.8125rem /* 45/16 */;
    line-height: 1;
    font-weight: 500;
    color: #000000
  }
  .user-desc {
    width: 50%;
    line-height: 2.25rem /* 36/16 */;
    color: #595757;
    font-size: 1.0625rem /* 17/16 */;
  }
}
.tech-user-photo {
  width: 100%;
  position: relative;
  .tech-user-tag {
    position: absolute;
    z-index: 10;
    right: 0;
    bottom: 0;
    background: #E50012;
    padding: 1.5625rem /* 25/16 */ 3.125rem /* 50/16 */;
    color: #FFFFFF;
    font-size: .9375rem /* 15/16 */;
  }
}
.lab-swiper {
  width: 50vw;
  height: 52vw;
  overflow: hidden;
  .swiper-slide {
    width: 100%;
    height: 32vw;
    /* &:first-child {
      margin-top: 6vw;
    }
    &:last-child {
      margin-bottom: 6vw;
    } */
  }
}
.lab-box {
  width: 100%;
  min-height: 100vh;
  position: relative;
  .lab-box-section {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    overflow: hidden;
    position: sticky;
    top: 0;
    z-index: 5;
  }
  .lab-item {
    width: 100vw;
    margin: 0 auto;
    display: flex;
    justify-content: flex-end;
    position: sticky;
    top: 0;
    background: url('@/assets/images/lab_bg.png') no-repeat center center/100% 100%;
    .lab-icon {
      position: absolute;
      bottom: 3.75rem /* 60/16 */;
      right: calc(50vw + 3.125rem /* 50/16 */);
      width: 3.125rem /* 50/16 */;
      height: 3.125rem /* 50/16 */;
      background: #E50012;
      border-radius: 50%;
      img {
        width: 50%;
        position: relative;
        top: .125rem /* 2/16 */
      }
    }
  }
  .lab-left {
    width: 83.33vw;
    margin: 0 auto;
    position: relative;
    z-index: 10;
    .text-wrapper {
      width: 26vw;
      margin-top: -25vw;
    }
  }
  .lab-card {
    width: 100%;
    &+.lab-card {
      margin-top: 25vw;
    }
    &:last-child {
      padding-bottom: 40vw;
    }
  }
  .lab-right {
    width: 50%;
    height: 100vh;
    position: sticky;
    top: 0;
    .lab-photo {
      position: absolute;
      width: 50vw;
      top: 0;
      left: 0;
      opacity: 0;
      transition: all .3s ease-in-out;
      &.active {
        opacity: 1;
      }
    }
  }
}
.lab-main {
  width: 100%;
  display: flex;
  justify-content: center;
  flex-direction: column;
  opacity: .3;
  cursor: pointer;
  &.active {
    opacity: 1;
  }
  .lab-tag {
    font-size: 1.125rem /* 18/16 */;
    line-height: 1;
    color: #333333;

  }
  .lab-title {
    margin-top: .9375rem /* 15/16 */;
    line-height: 1;
    font-weight: 500;
    font-size: 2.8125rem /* 45/16 */;
    color: #000000
  }
  .lab-line {
    width: 20.875rem /* 334/16 */;
    margin-top: 2.1875rem /* 35/16 */;
    height: 1px;
    background-color: #D3D3D3;
  }
  .lab-content {
    width: 100%;
    margin-top: 1.5rem /* 24/16 */;
    font-size: 1.125rem /* 18/16 */;
    line-height: 2.5rem /* 40/16 */;
    color: #595757;
  }
}
.patent-box {
  padding: 11.5625rem /* 185/16 */ 0 8rem /* 128/16 */;
  background: url('@/assets/images/yf_bg.png') no-repeat center center/100% 100%;
}
.patent-container {
  width: 83.3333vw;
  margin: 0 auto;
}
.patent-left {
  // width: 30.42vw;
  width: 36.25rem /* 580/16 */;
  padding-top: .75rem /* 12/16 */;
  .title {
    line-height: 1;
    font-weight: 500;
    font-size: 2.8125rem /* 45/16 */;
    color: #000000
  }
  .desc {
    margin-top: 3.4375rem /* 55/16 */;
    font-size: 1.125rem /* 18/16 */;
    line-height: 2.5rem /* 40/16 */;
    color: #595757;
  }
}
.patent-right {
  // width: 38.75vw;
  flex: 1;
  width: 0;
  margin-left: 9.9vw;
}
.patent-photos {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  .patent-item {
    width: 10.416vw;
    &+.patent-item {
      margin-left: 3.75vw;
    }
    .photo {
      width: 100%;
      img {
        width: 100%;
      }
    }
    .label {
      margin-top: 1.5625rem /* 25/16 */;
      font-size: .875rem /* 14/16 */;
      line-height: 2;
      text-align: center;
      color: #333333;
      white-space: nowrap;
    }
  }
}
.patent-hd {
  display: flex;
  align-items: center;
}
.patent-main {
  margin-top: 9.9375rem /* 159/16 */;
  margin-right: 6.56vw;
}
.patent-data {
  .key {
    font-size: 3.75rem /* 60/16 */;
    line-height: 1;
    letter-spacing: .02em;
    color: #E50012;
    font-weight: 500;
    display: flex;
    align-items: flex-end;
    .unit {
      font-size: 2.5rem /* 40/16 */;
      line-height: 3.75rem /* 60/16 */;;
    }
  }
  .title {
    margin-top: 1.625rem /* 26/16 */;
    color: #3D3D3D;
    font-size: 1rem /* 16/16 */;
    letter-spacing: .02em;
    line-height: 1;
  }
}
</style> 